package com.dh.blog.utils;

import com.dh.blog.vo.PagerVo;

/**
 * 对分页对象的工具类
 * @author David
 *
 */
public class PagerUtils {
	/**
	 * 确定页面显示范围
	 * @param pager
	 */
	public static void rangeMake(PagerVo pager){
		if(pager.getTotal()>0){
			int range = PagerVo.RANGE;
			int begin = 1;
			int end = 1;
			int num = pager.getNum();
			int pages = pager.getPages();
			if(pages<range){
				end = pages;
			}else if(num <= (range+1)/2){
				begin = 1;
				end = range;
			}else if(num>(pages-range/2)){
				begin = pages-range+1;
				end = pages;
			}else{
				begin = num - range/2;
				end = begin + range-1;
			}
			pager.setBegin(begin);
			pager.setEnd(end);
		}
	}
}
